package com.wondersgroup.fjzlpt.console.utils;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.nosql.mongodb.inter.IMongoFileOper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件操作帮助类
 * Created by lion on 2017/8/10.
 */
@Component
public class FileUtils {

    /*mongo文件操作*/
    @Autowired
    private IMongoFileOper mongoFileOper;

    /**
     * 保存上传图片到mongo和本地
     * @param mfile
     * @param fileField
     * @param mongoParams
     * @return
     */
    public String saveImageToMongoAndLocal(MultipartFile mfile, String fileField, JSONObject mongoParams) throws Exception {
        JSONObject params = new JSONObject();
        params.putAll(mongoParams);
        return mongoFileOper.saveFile(ControllerCommonUtils.mongo_imgaes_tablename, fileField, mfile, params, ControllerCommonUtils.filePath);
    }

    /**
     * 获取图片内容
     * @param contentField
     * @param fileId
     * @return
     * @throws Exception
     */
    public byte[] receiveImage(String contentField, String fileId) throws Exception {
        return mongoFileOper.receiveFile(ControllerCommonUtils.mongo_imgaes_tablename, contentField, fileId, ControllerCommonUtils.filePath);
    }
}















